/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slishome;

import java.io.*;

/**
 *
 * @author ITC
 */
public class ReadFromFile implements Globals {
    
    public String ReadFile(){
        
        try {
            BufferedReader in = new BufferedReader(new FileReader(txtFile));
            BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
            String lineToPrint = in.readLine();
            String currentLine;
            
            while((currentLine = in.readLine()) != null){
                String trimmedLine = currentLine.trim();
                if(trimmedLine.equals(lineToPrint)) continue;
                out.write(currentLine + "\n");
            }
            in.close();
            out.close();
            
            File f2 = new File(txtFile);
            f2.delete();
            File f = new File(tempFile);
            
            boolean successful = f.renameTo(f2);
            if(successful){
                return lineToPrint;
            }
            else{
                return "did not work correctly";
            }
        } catch (IOException e) {
            return "Could not read from file.";
        }      
    }
    
}
